
/**
 * 指定类型的部分属性为可选
 * @example
 * type A = { a: string, b: number, c: boolean,d: string[] }
 * type B = PartialByKeys<A, 'a' | 'b'> // { a?: string, b?: number, c: boolean,d: string[] }
 */
export type PartialByKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>


/**
 * 指定类型的部分属性为必选
 * @example
 * type A = { a?: string, b?: number, c: boolean,d: string[] }
 * type B = RequiredByKeys<A, 'a' | 'b'> // { a: string, b: number, c: boolean,d: string[] }
 */
export type RequiredByKeys<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>

/**
 * 获取API结果数据的类型
 */
export type ApiResultType<T extends (...ags: any[]) => Promise<ApiResult<any>>> = T extends (...args: any[]) => Promise<ApiResult<infer R>> ? R : never



export const enum Code {
    /**请求完成 */
    success = 0,
    /**参数错误 */
    validateError = 1,
    /**系统错误 */
    systemError = 500
}

export type SuccessApiResult<T> = {
    code: Code.success,
    data: T,
    msg: string,
}
export type ValidateApiResult = {
    code: Code.validateError,
    msg: string,
}
export type ErrorApiResult = {
    code: Code.systemError,
    msg: string,
    errorDetail: Record<string, any>
}
export type ApiResult<T> = SuccessApiResult<T> | ValidateApiResult | ErrorApiResult;